﻿// -----------------------------------------------------------------------------------------------
//  <copyright file="TfsTestItem.cs" company="http://buginbox.wordpress.com/">
//    Copyright (c) GNU General Public License version 2 (GPLv2)
//  </copyright>
// -----------------------------------------------------------------------------------------------

using Microsoft.TeamFoundation.TestManagement.Client;

namespace TestPlanMigration.Tree
{
    /// <summary>
    /// A test item. 
    /// </summary>
    public class TfsTestItem
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TfsTestItem"/> class.
        /// </summary>
        /// <param name="plan">The plan.</param>
        public TfsTestItem(ITestPlan plan)
        {
            Type = TfsTestItemType.TestPlan;
            TestPlan = plan;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TfsTestItem"/> class.
        /// </summary>
        /// <param name="suite">The suite.</param>
        public TfsTestItem(IStaticTestSuite suite)
        {
            Type = TfsTestItemType.TestSuite;
            TestSuite = suite;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TfsTestItem"/> class.
        /// </summary>
        /// <param name="testCase">The test case.</param>
        public TfsTestItem(ITestSuiteEntry testCase)
        {
            Type = TfsTestItemType.TestCase;
            TestCase = testCase;
        }

        /// <summary>
        /// Gets the type.
        /// </summary>
        public TfsTestItemType Type { get;  private set; }

        /// <summary>
        /// Gets the test plan
        /// </summary>
        public ITestPlan TestPlan { get; private set; }

        /// <summary>
        /// Gets the test suite
        /// </summary>
        public IStaticTestSuite TestSuite { get; private set; }

        /// <summary>
        /// Gets the test case
        /// </summary>
        public ITestSuiteEntry TestCase { get; private set; }

        /// <summary>
        /// Gets the ID.
        /// </summary>
        public int Id
        {
            get
            {
                switch (Type)
                {
                    case TfsTestItemType.TestPlan:
                        return TestPlan.Id;

                    case TfsTestItemType.TestSuite:
                        return TestSuite.Id;

                    case TfsTestItemType.TestCase:
                        return TestCase.Id;
                }

                return 0;
            }
        }

        /// <summary>
        /// Gets the Name.
        /// </summary>
        public string Name
        {
            get
            {
                switch (Type)
                {
                    case TfsTestItemType.TestPlan:
                        return TestPlan.Name;

                    case TfsTestItemType.TestSuite:
                        return TestSuite.Title;

                    case TfsTestItemType.TestCase:
                        return TestCase.Title;
                }

                return string.Empty;
            }
        }
    }
}